<!DOCTYPE HTML>
<html>
<head>
    <title>編輯</title>
    <link rel="stylesheet" href="/stylesheets/style.css">
    <script src="/scripts/jquery.min.js"></script>
    <script src="/scripts/boot.js" type="text/javascript"></script>
    <link rel="stylesheet" href="/scripts/miniui/themes/default/miniui.css">
    <link rel="stylesheet" href="/scripts/miniui/themes/icons.css">
    <link rel="stylesheet" href="/scripts/miniui/themes/bootstrap/skin.css">
    <link rel="stylesheet" href="/editor/common.css">
    <script src="/scripts/miniui/miniui.js"></script>
</head>
<body>
    <div id="form1" style="padding-left: 60px">
        <span style="width:60px;display:inline-block;">价格：</span>
        <input id="price" name="price" class="mini-textbox" required="true" type="number" style="width:155px;" value="<%= result.price%>" />
        <br/><br/>
        <span style="width:60px;display:inline-block;">积分：</span>
        <input id="score" name="score" class="mini-textbox" required="true"  type="number" style="width:155px;" value="<%= result.score%>"/>
        <br/><br/>
        <span style="width:60px;display:inline-block;">运费：</span>
        <input id="freight" name="freight" class="mini-textbox" required="true" type="number" style="width:155px;" value="<%= result.freight%>" />
        <br/><br/>
        <span style="width:60px;display:inline-block;">购买数量：</span>
        <input id="count" name="count" class="mini-textbox" required="true" type="number" style="width:155px;" value="<%= result.count%>" />
        <br/><br/>
        <span style="width:60px;display:inline-block;">赠送积分：</span>
        <input id="presentScore" name="presentScore" class="mini-textbox" required="true" type="number" style="width:155px;" value="<%= result.presentScore%>" />
        <br/><br/>
        <span style="width:60px;">商品分类：</span>
        <input id="btnSelectGoodsType" class="mini-buttonedit" onbuttonclick="onButtonSelectGoodsType" required="true" value="<%= result.shopGoodsTypeOId%>" text="<%= result.goodsType%>"/>
        <input id="pid" name="pid" class="mini-textbox" required="true" type="number" style="width:155px;display: none;" readonly="readonly" value="<%= result.shopGoodsTypeParentOId%>"/>
        <br/><br/>
        <span style="width:100px;display:inline-block;">是否是VIP商品：</span>
        <input id="isVip" name="isVip" class="mini-combobox" style="width:100px;" data="isVipData" value="<%= result.isVip%>"/>
        <br/><br/>
        <span style="width:60px;display:inline-block;">佣金总额：</span>
        <input id="brokerage" name="brokerage" class="mini-textbox" required="true" type="number" style="width:155px;" value="<%= result.brokerage%>" />
        <br/><br/>
        <span style="width:60px;display:inline-block;">上一级分成钱：</span>
        <input id="superiorMoney" name="superiorMoney" class="mini-textbox" required="true" type="number" style="width:155px;" value="<%= result.superiorMoney%>" onvaluechanged="priceChange"/>
        <br/><br/>
        <span style="width:60px;display:inline-block;">上二级分成钱：</span>
        <input id="superiorSuperiorMoney" name="superiorSuperiorMoney" class="mini-textbox" required="true" type="number" style="width:155px;" value="<%= result.superiorSuperiorMoney%>" />
        <br/><br/>
        <span style="width:60px;display:inline-block;">上三级分成钱：</span>
        <input id="superiorSuperiorSuperiorMoney" name="superiorSuperiorSuperiorMoney" class="mini-textbox" required="true" type="number" style="width:155px;" value="<%= result.superiorSuperiorSuperiorMoney%>" />
        <br/><br/>
        <span style="width:60px;display:inline-block;">上三级祖辈分成钱：</span>
        <input id="ancestorsMoney" name="ancestorsMoney" class="mini-textbox" required="true" type="number" style="width:155px;" value="<%= result.ancestorsMoney%>" />
        <br/><br/>
        <span style="width:60px;display:inline-block;">上一级分成积分比例：</span>
        <input id="superiorScore" name="superiorScore" class="mini-textbox" required="true" type="number" style="width:155px;" value="<%= result.superiorScore%>" />
        <br/><br/>
        <span style="width:60px;display:inline-block;">上二级分成积分比例：</span>
        <input id="superiorSuperiorScore" name="superiorSuperiorScore" class="mini-textbox" required="true" type="number" style="width:155px;" value="<%= result.superiorSuperiorScore%>" />
        <br/><br/>
        <!--<span style="width:60px;display:inline-block;">上三级分成积分比例：</span>-->
        <!--<input id="superiorSuperiorSuperiorScore" name="superiorSuperiorSuperiorScore" class="mini-textbox" required="true" type="number" style="width:155px;" value="<%= result.superiorSuperiorSuperiorScore%>" />-->
        <!--<br/><br/>-->
        <span style="width:60px;display:inline-block;">上二级祖辈分成积分比例：</span>
        <input id="ancestorsScore" name="ancestorsScore" class="mini-textbox" required="true" type="number" style="width:155px;" value="<%= result.ancestorsScore%>" />
    </div>
    <div style="margin: 30px 0;text-align: center">
        <a class="mini-button " iconCls="icon-ok" onclick="editScoreGoodShop()">确定</a>
        <a class="mini-button" iconCls="icon-cancel" onclick="onCancel">取消</a>
    </div>
</body>
<script>
    var objectId = '<%=result.objectId%>';
    var isVipData= [{id:0,text:'否'},{id:1,text:'是'}];
    mini.parse();
    function editScoreGoodShop() {
        var form = new mini.Form("#form1");
        form.validate();
        if (form.isValid() == false) return;
      var data = {}
      // data.shopGoodsOId = mini.get("btnEdit1").getValue();
      data.objectId = objectId
        data.isVip = mini.get("isVip").getValue();
      data.price = mini.get("price").getValue();
      data.score = mini.get("score").getValue();
      data.freight = mini.get("freight").getValue();
      data.count = mini.get("count").getValue();
      data.presentScore = mini.get("presentScore").getValue();
      data.superiorMoney = mini.get("superiorMoney").getValue();
      data.superiorSuperiorMoney = mini.get("superiorSuperiorMoney").getValue();
      data.superiorSuperiorSuperiorMoney = mini.get("superiorSuperiorSuperiorMoney").getValue();
      data.ancestorsMoney = mini.get("ancestorsMoney").getValue();
      data.superiorScore = mini.get("superiorScore").getValue();
      data.superiorSuperiorScore = mini.get("superiorSuperiorScore").getValue();
      // data.superiorSuperiorSuperiorScore = mini.get("superiorSuperiorSuperiorScore").getValue();
      data.ancestorsScore = mini.get("ancestorsScore").getValue();
      data.goodsTypeOId = mini.get("btnSelectGoodsType").getValue();
      data.goodsTypePId = mini.get("pid").getValue();
      data.brokerage = mini.get("brokerage").getValue();
      // console.log(data)
        $.ajax({
            type: "POST",
            url: "/getdata/editScoreGoodsShop",
            data: data,
            success: function (result) {
                if(result =="1"){
                    alert("更新成功");
                    CloseWindow("save");
                }else{
                    alert("更新失敗")
                    CloseWindow("save");
                }

            }
        })
    }
    //    关闭窗口
    function CloseWindow(action) {
        if (action == "close" && form.isChanged()) {
            if (confirm("数据被修改了，是否先保存？")) {
                return false;
            }
        }
        if (window.CloseOwnerWindow) return window.CloseOwnerWindow(action);
        else window.close();
    }

    function onCancel(e) {
        CloseWindow("cancel");
    }
    function priceChange() {
      var price = mini.get("superiorMoney").getValue()
      var superiorSuperiorMoney = Math.floor(Number(price) * 0.6 *100)/100
      mini.get('superiorSuperiorMoney').setValue(superiorSuperiorMoney.toFixed(2));
      var ancestorsMoney = Math.floor(Number(price) * 0.2 *100)/100
      mini.get('superiorSuperiorSuperiorMoney').setValue(ancestorsMoney.toFixed(2));
      var ancestorsMoney = Math.floor(Number(price) * 0.2 *100)/100
      mini.get('ancestorsMoney').setValue(ancestorsMoney.toFixed(2));
    }
    function onButtonSelectGoodsType(e) {
      var btnSelectGoodsType = this;
      mini.open({
        url: "/getdata/shopIntergationSelectGoodsType",
        showMaxButton: false,
        title: "选择商品分类",
        width: 350,
        height: 350,
        ondestroy: function (action) {
          if (action == "ok") {
            var iframe = this.getIFrameEl();
            var data = iframe.contentWindow.GetData();
            data = mini.clone(data);
            if (data) {
              // console.log(data)
              btnSelectGoodsType.setValue(data.id);
              btnSelectGoodsType.setText(data.text);
              mini.get('pid').setValue(data.pid);
            }
          }
        }
      });
    }
</script>
</html>